package com.baidu.tracks.mylogin;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;


import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.model.LatLng;
import com.baidu.tracks.R;

public class MapActivity extends AppCompatActivity {
    private MapView mapView;
    //private LocationClient mLocationClient;
    private BaiduMap mBaiduMap = null;
    private boolean isFirstLoc = true;

    //声明地图组件
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        mapView = findViewById(R.id.bmapview);
        mBaiduMap = mapView.getMap();
        mBaiduMap.setMyLocationEnabled(true);
        //initLocation();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 退出时销毁定位
        //mLocationClient.stop();
        // 关闭定位图层
        mBaiduMap.setMyLocationEnabled(false);
        // 在activity执行onDestroy时必须调用mMapView.onDestroy()
        mapView.onDestroy();
    }
    /**
     * 定位SDK监听函数
     */
    /**
     * 定位SDK监听函数
     */
   /* public class MyLocationListener extends BDAbstractLocationListener {
        @Override
        public void onReceiveLocation(BDLocation location) {
            //mapView 销毁后不在处理新接收的位置
            if (location == null || mapView == null){
                return;
            }
            String addr = location.getAddrStr();    //获取详细地址信息
            String country = location.getCountry();    //获取国家
            String province = location.getProvince();    //获取省份
            String city = location.getCity();    //获取城市
            String district = location.getDistrict();    //获取区县
            String street = location.getStreet();    //获取街道信息
            String adcode = location.getAdCode();    //获取adcode
            String town = location.getTown();    //获取乡镇信息
            Log.e("TAG", "onReceiveLocation: "+addr+" country:"+country
                    +" province:"+province+" city:"+city+" district:"+district+" street:"+street+" adcode:"+
                    adcode+" town:"+town+"  "+location.getLatitude()+"  "+" "+
                    location.getLongitude());
            MyLocationData locData = new MyLocationData.Builder()
                    .accuracy(location.getRadius())
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(location.getDirection()).latitude(location.getLatitude())
                    .longitude(location.getLongitude()).build();
            mBaiduMap.setMyLocationData(locData);
            if (isFirstLoc) {
                isFirstLoc = false;
                LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
                MapStatus.Builder builder = new MapStatus.Builder();
                builder.target(latLng).zoom(20.0f);
                mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
            }

        }
    }*/
    /**
     * 定位初始化
     */
    /*public void initLocation() {
        //定位初始化
        try {
            LocationClient.setAgreePrivacy(true);

            mLocationClient = new LocationClient(this);
            LocationClientOption locationClientOption = new LocationClientOption();
            // 可选，设置定位模式，默认高精度 LocationMode.Hight_Accuracy：高精度；
            locationClientOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
            /// 设置是否进行单次定位，单次定位时调用start之后会默认返回一次定位结果
            locationClientOption.setCoorType("bd09ll"); // 设置坐标类型
            locationClientOption.setScanSpan(5000);
            locationClientOption.setAddrType("all");
            locationClientOption.setOpenGps(true);
            // 设置定位参数
            mLocationClient.setLocOption(locationClientOption);
            MyLocationListener myLocationListener = new MyLocationListener();
            mLocationClient.registerLocationListener(myLocationListener);
            // 开启定位
            mLocationClient.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/




}